﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using sqlservice.util;
using sqlservice.service;
using sqlservice.bean;
namespace sqlservice
{
    public partial class Form1 : Form
    {
        private GradeService gradeService;
        public Form1()
        {
            InitializeComponent();

            gradeService = new GradeService();
        }

        /// <summary>
        /// 打开数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {

            // MessageBox.Show();
           // String info = DBHelper.connect();
            String info = gradeService.connectServer();
            richTextBox1.Text = info;

        }
        /// <summary>
        /// 关闭数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            // MessageBox.Show();
           // String info = DBHelper.close();
            String info = gradeService.closeServer();
            richTextBox1.Text = info;
        }

        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            String info = "姓名                 学号              chinese              english                  math";
            String sql = comboBox1.Text;
            List<Grade> grades = gradeService.selectGrades(sql);
            // MessageBox.Show(grades[0].Name);
            for (int i = 0; i < grades.Count; i++) {
                info += "\n" + grades[i].Name + "            "
                    + grades[i].Number + "           "
                    + grades[i].Chinese + "           "
                    + grades[i].English + "          "
                    + grades[i].Math; 
            }
            richTextBox1.Text = info;
        }

        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            String sql = comboBox1.Text;
            String info = gradeService.updateGrade(sql);
            richTextBox1.Text = info;
        }

        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            String sql = comboBox1.Text;
            String info =gradeService.insertGrade(sql);
            richTextBox1.Text = info;
        }
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            String sql = comboBox1.Text;
            String info = gradeService.deleteGrade(sql);
            richTextBox1.Text = info;
        }
    }
}
